package com.yuanqi.java.controller;

import com.yuanqi.java.entity.PurchaseReturnOrderAudit;
import com.yuanqi.java.result.Result;
import com.yuanqi.java.service.IPurchaseReturnOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/purchase-return-order-audit")
@RequiredArgsConstructor
public class PurchaseReturnOrderAuditController {

	private final IPurchaseReturnOrderService purchaseReturnOrderService;

	/**
	 * 审核退货单
	 */
	@PostMapping("/audit/{returnOrderId}")
	public Result<Boolean> audit(@PathVariable Long returnOrderId,
	                             @RequestParam Long auditorId,
	                             @RequestParam(required = false) String auditOpinion,
	                             @RequestParam Integer auditResult) {
		purchaseReturnOrderService.auditReturnOrder(returnOrderId, auditorId, auditOpinion, auditResult);
		return Result.success(true);
	}

	/**
	 * 获取审核记录
	 */
	@GetMapping("/record/{returnOrderId}")
	public Result<PurchaseReturnOrderAudit> record(@PathVariable Long returnOrderId) {
		PurchaseReturnOrderAudit audit = purchaseReturnOrderService.getLatestAuditRecord(returnOrderId);
		return Result.success(audit);
	}
} 